﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace CheckFreeWayServer
{
    public class Principal
    {
        Dictionary<int, ServidorSocket> dctServidorSocket =  new Dictionary<int,ServidorSocket>();

        int _intPortaInicial;
        int _intPortaFinal;

        public Principal()
        {
            Configuracao Config = new Configuracao();
            _intPortaInicial = Config.GetPortaInicial();
            _intPortaFinal = Config.GetPortaFinal();
        }


        public void Start()
        {
            for (int idx = _intPortaInicial; idx <= _intPortaFinal; idx++)
            {
                ServidorSocket sckServ = new ServidorSocket(idx);
                Thread thr = new Thread(new ThreadStart(sckServ.Run));
                thr.Start();
                dctServidorSocket.Add(idx, sckServ);
                Thread.Sleep(1);
            }
        }

        public void Stop()
        {
            foreach (ServidorSocket sckServ in dctServidorSocket.Values)
            {
                sckServ.StopRun();
            }
        }
    }
}
